package com.dcbeida.activity.addnewpatient;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.activity.BaseActivity;
import com.dcbeida.activity.CommonListActivity;
import com.dcbeida.activity.addnewpatient.historyofsmoking.HistoryOfSmoking;
import com.dcbeida.activity.addnewpatient.historyofsmoking.TypeAct;
import com.dcbeida.activity.hospital.HospitalActivity;
import com.dcbeida.activity.sign.SignQrCodeActivity;
import com.dcbeida.bean.AddPatient;
import com.dcbeida.bean.Area;
import com.dcbeida.bean.CardEnum;
import com.dcbeida.bean.HistoryOfSmokingBean;
import com.dcbeida.bean.HospitalBean;
import com.dcbeida.bean.MyClientBean;
import com.dcbeida.bean.NewPatient;
import com.dcbeida.bean.Pathology;
import com.dcbeida.bean.Regionname;
import com.dcbeida.bean.Tag;
import com.dcbeida.listern.DialogListener;
import com.dcbeida.utils.Constants;
import com.dcbeida.utils.DialogUtils;
import com.dcbeida.utils.GsonUtil;
import com.dcbeida.utils.Utils;
import com.dcbeida.widget.AreaWheelDialog;
import com.dcbeida.widget.DateSelectDialog;
import com.dcbeida.widget.DateSelectDialog.DateSelectListener;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * 新增患者
 * Created by swt on 2017/9/5.
 */

public class AddNewPatientAct extends BaseActivity implements AddNewPatientContract.View {
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRright;
    @Bind(R.id.rel_title1)
    RelativeLayout relTitle1;
    @Bind(R.id.et_name)
    EditText etName;
    @Bind(R.id.et_sfz)
    EditText etSfz;
    @Bind(R.id.tv_xb)
    TextView tvXb;
    @Bind(R.id.ll_xb)
    LinearLayout llXb;
    @Bind(R.id.tv_sr)
    TextView tvSr;
    @Bind(R.id.ll_sr)
    LinearLayout llSr;
    @Bind(R.id.et_sjh)
    EditText etSjh;
    @Bind(R.id.tv_zzqy)
    TextView tvZzqy;
    @Bind(R.id.ll_zzqy)
    LinearLayout llZzqy;
    @Bind(R.id.et_zzys)
    EditText etZzys;
    @Bind(R.id.tv_yymc)
    TextView tvYymc;
    @Bind(R.id.ll_yymc)
    LinearLayout llYymc;
    @Bind(R.id.tv_xys)
    TextView tvXys;
    @Bind(R.id.ll_xys)
    LinearLayout llXys;
    @Bind(R.id.tv_blfx)
    TextView tvBlfx;
    @Bind(R.id.ll_blfx)
    LinearLayout llBlfx;
    @Bind(R.id.tv_yyxs)
    TextView tvYyxs;
    @Bind(R.id.ll_yyxs)
    LinearLayout llYyxs;
    @Bind(R.id.tv_scyysj)
    TextView tvScyysj;
    @Bind(R.id.ll_scyysj)
    LinearLayout llScyysj;
    @Bind(R.id.tv_qrxz)
    TextView tvQrxz;
    @Bind(R.id.et_xxdz)
    TextView etXxdz;

    @Bind(R.id.ll_credit_type)
    LinearLayout ll_credit_type;
    @Bind(R.id.tv_crdeit_type)
    TextView tv_crdeit_type;
    @Bind(R.id.ll_tel_type)
    LinearLayout ll_tel_type;
    @Bind(R.id.tv_tel_type)
    TextView tv_tel_type;

    private String xys = "";
    private String xysYear = "";
    private int itemIndex;
    private DateSelectDialog dialog;
    private Calendar clCalendar;
    private Calendar clCalendar2;

    private AreaWheelDialog areaWheelDialog;
    private Area currentProvince;
    private Area currentCity;
    private Area currentArea;
    private HospitalBean hospitalBean;
    private int hospitalid;
    private int index = -1;
    private HistoryOfSmokingBean.ListBean historyOfSmokingBean;
    private List<Tag> typeSelectedTags;
    private List<Tag> yyxsSelectedTags;
    private String otherString = "";
    private String yyxsOtherString;
    private DateSelectDialog dialog2;
    String provinceS = "";
    String cityS = "";
    String areaS = "";
    String patient = "";
    private AddNewPatientPresenter presenter;
    private String sex = "";
    private MyClientBean myClientBean;
    private List<Pathology.TypeBean> type;
    private List<Pathology.SeverallinesBean> severallines;

    private int creditType=0;//默认0

    private int telType = 0;


    private int operaterType = 0; //新增


    @Override
    protected int getLayoutResId() {
        return R.layout.add_new_patient;
    }

    @Override
    public void setData() {
        Bundle bundle = getIntent().getExtras();

        if(null != bundle){
            myClientBean = (MyClientBean) bundle.getSerializable("myClientBean");
            operaterType = bundle.getInt("operaterType",0);
            if(operaterType == 0){
                tvQrxz.setVisibility(View.VISIBLE);
                tvRright.setVisibility(View.GONE);
                tvTitle.setText(R.string.xzhz);
                setText(myClientBean);
            }else if(operaterType ==1){
                tvQrxz.setVisibility(View.GONE);
                tvRright.setVisibility(View.VISIBLE);
                tvRright.setText(R.string.bc);
                tvTitle.setText(R.string.bjhz);
                setText(myClientBean);
            }

        }else {
            tvQrxz.setVisibility(View.VISIBLE);
            tvRright.setVisibility(View.GONE);
            tvTitle.setText(R.string.xzhz);
        }


        imgBack.setVisibility(View.VISIBLE);
        tvTitle.setVisibility(View.VISIBLE);
        clCalendar = Calendar.getInstance();
        clCalendar2 = Calendar.getInstance();
        typeSelectedTags = new ArrayList<>();
        yyxsSelectedTags = new ArrayList<>();
        presenter = new AddNewPatientPresenter(this, this);
    }

    @OnClick({R.id.img_back, R.id.tv_right, R.id.ll_xb, R.id.ll_sr, R.id.ll_zzqy, R.id.ll_yymc, R.id.ll_xys, R.id.ll_blfx, R.id.ll_yyxs, R.id.ll_scyysj, R.id.tv_qrxz,R.id.ll_credit_type,R.id.ll_tel_type})
    public void onClick(View view) {
        Bundle bundle = new Bundle();
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.ll_xb:
                //吸烟史
                bundle.putString("sex", sex);
                showActivityForResult(SexAct.class, bundle, Constants.FOUR);
                break;
            case R.id.ll_credit_type:
                bundle = new Bundle();
                bundle.putInt("type", 0);
                showActivityForResult(CommonListActivity.class, bundle, Constants.RESULT_CRIDET_TYPE);
                break;
            case R.id.ll_tel_type:
                bundle = new Bundle();
                bundle.putInt("type", 1);
                showActivityForResult(CommonListActivity.class, bundle, Constants.RESULT_TEL_TYPE);
                break;
            case R.id.ll_sr:
                if (dialog == null) {
                    dialog = new DateSelectDialog(AddNewPatientAct.this, listener, "");
                }
                dialog.setDate(clCalendar);
                dialog.show();
                break;
            case R.id.ll_zzqy:
                setSSQ();
                break;
            case R.id.ll_yymc:
                showActivityForResult(HospitalActivity.class, bundle, Constants.HOSPITAL_TYPE);
                break;
            case R.id.ll_xys:
                //吸烟史
                bundle.putString("xys", xys);
                bundle.putString("xysYear", xysYear);
                bundle.putInt("itemIndex", itemIndex);
                bundle.putInt("index", index);
                showActivityForResult(HistoryOfSmoking.class, bundle, Constants.ONE);
                break;
            case R.id.ll_blfx:
                bundle.putString("title", getString(R.string.blfx));
                bundle.putString("parentid", "5");
                bundle.putString("otherString", otherString);
                bundle.putParcelableArrayList("typeSelectedTags", (ArrayList<? extends Parcelable>) typeSelectedTags);
                showActivityForResult(TypeAct.class, bundle, Constants.TWO);
                break;
            case R.id.ll_yyxs:
                bundle.putString("title", getString(R.string.yyxs));
                bundle.putString("parentid", "12");
                bundle.putString("yyxsOtherString", yyxsOtherString);
                bundle.putParcelableArrayList("yyxsSelectedTags", (ArrayList<? extends Parcelable>) yyxsSelectedTags);
                showActivityForResult(TypeAct.class, bundle, Constants.THREE);
                break;
            case R.id.ll_scyysj:
                if (dialog2 == null) {
                    dialog2 = new DateSelectDialog(AddNewPatientAct.this, listener2, "");
                }
                dialog2.setDate(clCalendar2);
                dialog2.show();
                break;
            case R.id.tv_right:
            case R.id.tv_qrxz:
                if (TextUtils.isEmpty(etName.getText().toString().trim())) {
                    showTip("请输入姓名");
                    return;
                }


                if (hospitalid ==0) {
                    showTip("请选择医院");
                    return;
                }
//
//                if (TextUtils.isEmpty(etSjh.getText().toString().trim())) {
//                    showTip("请输入联系方式");
//                    return;
//                }

                if (telType == 0 && !TextUtils.isEmpty(etSjh.getText().toString().trim()) &&etSjh.getText().toString().length() !=11) {
                    showTip("请正确填写患者手机号码");
                    return;
                }

                if (telType == 1 && !TextUtils.isEmpty(etSjh.getText().toString().trim()) && !etSjh.getText().toString().contains("-")) {
                    showTip("请正确填写患者固定电话");
                    return;
                }

                //确认新增
                NewPatient bean = new NewPatient();
                //编辑患者
                if (null != myClientBean && operaterType == 1) {
                    bean.setId(myClientBean.getId() + "");
                }else{
//                    if (TextUtils.isEmpty(etSfz.getText().toString().trim())) {
//                        showTip("请填写患者证件号");
//                        return;
//                    }
                    if (creditType == 0 && !TextUtils.isEmpty(etSfz.getText().toString().trim()) &&etSfz.getText().toString().length() != 18) {
                        showTip("请填写正确的身份证");
                        return;
                    }
                }
                assemableBean(bean);

                //Gson gson = new Gson();
                //patient = gson.toJson(bean);
                //Log.i("swt", patient);
                //                patient="{\"address\":\"农村\",\"birthday\":\"2017-10-24\",\"doctorname\":\"医生1\",\"firsttreatmentdate\":\"2017-10-24\",\"idcardnum\":\"123456789123456789\",\"pathology\":{\"severallines\":[{\"id\":\"13\",\"name\":\"一线\",\"value\":1},{\"id\":\"14\",\"name\":\"二线\",\"value\":2},{\"id\":\"15\",\"name\":\"三线\",\"value\":3}],\"type\":[{\"id\":\"7\",\"name\":\"腺癌\",\"value\":2},{\"id\":\"8\",\"name\":\"腺鳞癌\",\"value\":3},{\"id\":\"6\",\"name\":\"鳞癌\",\"value\":1},{\"id\":\"9\",\"name\":\"大细胞癌\",\"value\":4}]},\"phonenum\":\"15222222222\",\"regionname\":{\"area\":\"道里区\",\"city\":\"哈尔滨市 \",\"province\":\"黑龙江省\"},\"smokestatus\":\"0\",\"smokeyears\":\"\",\"truename\":\"张杰\",\"cityid\":0,\"doctorid\":0,\"hospitalid\":4,\"provinceid\":0,\"referid\":0,\"regionid\":0,\"sex\":1}";

                //如果是编辑患者 todo
                if (null != myClientBean && operaterType == 1) {
                    if (TextUtils.isEmpty(etSjh.getText().toString().trim())) {
                        showTip("请输入联系方式");
                        return;
                    }
                    if (TextUtils.isEmpty(etSfz.getText().toString().trim())) {
                        showTip("请填写患者证件号");
                        return;
                    }
                    presenter.getData(bean);
                }

                if(TextUtils.isEmpty(etSjh.getText().toString().trim()) || TextUtils.isEmpty(etSfz.getText().toString().trim())){
                    DialogUtils.showSign(this,listener19);
                }else {
                    presenter.getData(bean);
                }
                break;
        }
    }



    private void assemableBean(NewPatient bean){
        if (null != myClientBean && operaterType == 1) {
            bean.setId(myClientBean.getId() + "");
        }
        bean.setCardtype(creditType);
        bean.setTruename(etName.getText().toString().trim());
        bean.setIdcardnum(etSfz.getText().toString().trim());
        if (getString(R.string.nan).equals(sex)) {
            //男
            bean.setSex(1);
        } else if (getString(R.string.nv).equals(sex)) {
            //女
            bean.setSex(2);
        } else if (getString(R.string.zx).equals(sex)) {
            //中性
            bean.setSex(0);
        }
        bean.setBirthday(tvSr.getText().toString() + "");
        bean.setPhonenum(etSjh.getText().toString().trim());
        //省市区
        NewPatient.RegionnameBean regionnameBean = new NewPatient.RegionnameBean();
        regionnameBean.setProvince(provinceS + "");
        regionnameBean.setCity(cityS + "");
        regionnameBean.setArea(areaS + "");
        bean.setRegionname(regionnameBean);
        bean.setAddress(etXxdz.getText().toString().trim() + "");
        if (null != historyOfSmokingBean) {
            bean.setSmokestatus(historyOfSmokingBean.getValue() + "");
            bean.setSmokeyears(xysYear);
        }
        NewPatient.PathologyBean pathologyBean = new NewPatient.PathologyBean();


        List<NewPatient.PathologyBean.TypeBean> typeBeen = new ArrayList<NewPatient.PathologyBean.TypeBean>();
        for (int i = 0; i < typeSelectedTags.size(); i++) {
            Tag tag = typeSelectedTags.get(i);

            NewPatient.PathologyBean.TypeBean typeBean = new NewPatient.PathologyBean.TypeBean();
            typeBean.setId(tag.getLableId());
            if (tag.getOrgId().equals("99")) {
                typeBean.setName(tag.getOther());
            } else {
                typeBean.setName(tag.getLableDesc());
            }
            typeBean.setValue(Integer.parseInt(tag.getOrgId()));
            typeBeen.add(typeBean);
        }

        List<NewPatient.PathologyBean.SeverallinesBean> severallinesBeanList = new ArrayList<NewPatient.PathologyBean.SeverallinesBean>();
        for (int i = 0; i < yyxsSelectedTags.size(); i++) {
            Tag tag = yyxsSelectedTags.get(i);
            NewPatient.PathologyBean.SeverallinesBean severallinesBean = new NewPatient.PathologyBean.SeverallinesBean();
            severallinesBean.setId(tag.getLableId());
            if (tag.getOrgId().equals("99")) {
                severallinesBean.setName(tag.getOther());
            } else {
                severallinesBean.setName(tag.getLableDesc());
            }
            severallinesBean.setValue(Integer.parseInt(tag.getOrgId()));
            severallinesBeanList.add(severallinesBean);
        }

        pathologyBean.setType(typeBeen);
        if (null != typeBeen && typeBeen.size() > 0) {

        } else {
            if (null != type) {
                for (int i = 0; i < type.size(); i++) {
                    NewPatient.PathologyBean.TypeBean typeBean = new NewPatient.PathologyBean.TypeBean();
                    typeBean.setId(type.get(i).getId());
                    typeBean.setName(type.get(i).getName());
                    typeBean.setValue(type.get(i).getValue());
                    typeBeen.add(typeBean);
                }
                pathologyBean.setType(typeBeen);
            }

        }
        pathologyBean.setSeverallines(severallinesBeanList);
        if (null != severallinesBeanList && severallinesBeanList.size() > 0) {

        } else {
            if (null != severallines) {
                for (int i = 0; i < severallines.size(); i++) {
                    NewPatient.PathologyBean.SeverallinesBean severallinesBean = new NewPatient.PathologyBean.SeverallinesBean();
                    severallinesBean.setId(severallines.get(i).getId());
                    severallinesBean.setName(severallines.get(i).getName());
                    severallinesBean.setValue(severallines.get(i).getValue());
                    severallinesBeanList.add(severallinesBean);
                }
                pathologyBean.setSeverallines(severallinesBeanList);
            }

        }
        bean.setPathology(pathologyBean);
        bean.setDoctorname(etZzys.getText().toString().trim());
        bean.setHospitalid(hospitalid);//医院名称
        bean.setSmokeyears(xysYear);//吸烟史
        bean.setFirsttreatmentdate(tvScyysj.getText().toString().trim());
    }

    private DialogListener listener19= new DialogListener() {
        @Override
        public void onCancl(Dialog dialog) {
            dialog.dismiss();
            NewPatient bean = new NewPatient();
            assemableBean(bean);
            bean.setCardtype(CardEnum.ZRXLHZ.getType());
            creditType = CardEnum.ZRXLHZ.getType();
            presenter.getData(bean);
        }

        @Override
        public void onConfirm(Dialog dialog) {
            dialog.dismiss();
        }
    };

    private void setSSQ() {
        if (areaWheelDialog == null) {
            areaWheelDialog = new AreaWheelDialog(AddNewPatientAct.this);
            areaWheelDialog.setListener(new AreaWheelDialog.AreaSelectListener() {
                @Override
                public void area_selected(Area province, Area city, Area area) {
                    currentProvince = province;
                    currentCity = city;
                    currentArea = area;


                    String provinceStr = "";
                    String cityStr = "";
                    String areaStr = "";
                    if (!TextUtils.isEmpty(province.getName()) && !"市辖区".equalsIgnoreCase(province.getName()) && !"县".equalsIgnoreCase(province.getName()))
                        provinceStr = province.getName() + " ";
                    provinceS = province.getName();
                    if (city != null && !TextUtils.isEmpty(city.getName()) && !"市辖区".equalsIgnoreCase(city.getName()) && !"县".equalsIgnoreCase(city.getName()))
                        cityStr = city.getName() + " ";
                    cityS = city.getName();
                    if (area != null && !TextUtils.isEmpty(area.getName()) && !"市辖区".equalsIgnoreCase(area.getName()) && !"县".equalsIgnoreCase(area.getName()))
                        areaStr = area.getName();
                    areaS = area.getName();


                    tvZzqy.setText(provinceStr + cityStr + areaStr);
                }
            });
        }

        if (currentProvince != null && currentCity != null && currentArea != null) {
            areaWheelDialog.showDialog(provinceS, cityS, areaS);
        } else {
            areaWheelDialog.showDialog(provinceS, cityS, areaS);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Constants.ONE && resultCode == RESULT_OK) {
            Bundle bundle = data.getExtras();
            if (null != bundle) {
                xys = bundle.getString("xys");
                xysYear = bundle.getString("xysYear");
                itemIndex = bundle.getInt("itemIndex");
                index = bundle.getInt("index");
                historyOfSmokingBean = (HistoryOfSmokingBean.ListBean) bundle.getSerializable("HistoryOfSmokingBean");
                tvXys.setText(xys + xysYear);
            }
        } else if (requestCode == Constants.TWO && resultCode == RESULT_OK) {
            Bundle bundle = data.getExtras();
            if (null != bundle) {
                String blfx = "";
                typeSelectedTags = bundle.getParcelableArrayList("typeSelectedTags");
                otherString = bundle.getString("otherString");
                for (int i = 0; i < typeSelectedTags.size(); i++) {

                    if (i != 0 && i != typeSelectedTags.size()) {
                        if (!TextUtils.isEmpty(typeSelectedTags.get(i).getOther()))
                            blfx = blfx + "," + typeSelectedTags.get(i).getOther();
                        else
                            blfx = blfx + "," + typeSelectedTags.get(i).getLableDesc();
                    } else {
                        if (!TextUtils.isEmpty(typeSelectedTags.get(i).getOther()))
                            blfx = typeSelectedTags.get(i).getOther();
                        else
                            blfx = typeSelectedTags.get(i).getLableDesc();
                    }


                }

                tvBlfx.setText(blfx);
            }
        } else if (requestCode == Constants.THREE && resultCode == RESULT_OK) {
            Bundle bundle = data.getExtras();
            if (null != bundle) {
                String yyxs = "";
                yyxsSelectedTags = bundle.getParcelableArrayList("yyxsSelectedTags");
                yyxsOtherString = bundle.getString("yyxsOtherString");
                for (int i = 0; i < yyxsSelectedTags.size(); i++) {

                    if (i != 0 && i != yyxsSelectedTags.size()) {
                        if (!TextUtils.isEmpty(yyxsSelectedTags.get(i).getOther()))
                            yyxs = yyxs + "," + yyxsSelectedTags.get(i).getOther();
                        else
                            yyxs = yyxs + "," + yyxsSelectedTags.get(i).getLableDesc();
                    } else {
                        if (!TextUtils.isEmpty(yyxsSelectedTags.get(i).getOther()))
                            yyxs = yyxsSelectedTags.get(i).getOther();
                        else
                            yyxs = yyxsSelectedTags.get(i).getLableDesc();
                    }

                }

                tvYyxs.setText(yyxs);
            }
        } else if (requestCode == Constants.HOSPITAL_TYPE && resultCode == RESULT_OK) {//选择医院
            Bundle bundle = data.getExtras();
            if (null != bundle) {
                if (bundle.containsKey("hospitalBean")) {
                    hospitalBean = (HospitalBean) bundle.getSerializable("hospitalBean");
                    tvYymc.setText(hospitalBean.getHospitalname());
                    hospitalid = hospitalBean.getHospitalid();
                }
            }

        } else if (requestCode == Constants.FOUR && resultCode == RESULT_OK) {//选择医院
            Bundle bundle = data.getExtras();
            if (null != bundle) {
                if (bundle.containsKey("sex")) {
                    sex = bundle.getString("sex");
                    tvXb.setText(sex);
                }
            }

        }else if (resultCode == RESULT_OK && requestCode == Constants.RESULT_CRIDET_TYPE){
            String key = data.getStringExtra("key");
            tv_crdeit_type.setText(key);
            creditType = data.getIntExtra("value",0);
        }else if(resultCode == RESULT_OK && requestCode == Constants.RESULT_TEL_TYPE){
            String key = data.getStringExtra("key");
            tv_tel_type.setText(key);
            telType = data.getIntExtra("value",0);
        }
        else if(resultCode == RESULT_OK && requestCode == Constants.REQUEST_ADD_PATIENT_SIGN){
            if(operaterType == 0){
                if(null != myClientBean){
                    Intent intent = new Intent();
                    Bundle bundle = new Bundle();
                    bundle.putInt("patientId", myClientBean.getId());
                    intent.putExtras(bundle);
                    setResult(RESULT_OK, intent);
                }
                finish();
            }
        }
    }

    private String time;
    DateSelectListener listener = new DateSelectListener() {

        @Override
        public void dateSelect(Calendar clCalendar) {
            String date = Utils.getDateStr2(clCalendar);
            AddNewPatientAct.this.clCalendar = clCalendar;
            time = date;
            tvSr.setText(time);
        }
    };
    private String time2;
    DateSelectListener listener2 = new DateSelectListener() {

        @Override
        public void dateSelect(Calendar clCalendar) {
            String date = Utils.getDateStr2(clCalendar);
            AddNewPatientAct.this.clCalendar2 = clCalendar;
            time2 = date;
            tvScyysj.setText(time2);
        }
    };

    @Override
    public void setPresenter(AddNewPatientContract.Present presenter) {

    }

    @Override
    public void getDataError(String msg, int type) {

    }

    @Override
    public void getDataSuccess(AddPatient addPatient) {
        if (null != myClientBean && operaterType == 1) {

            showTip(getString(R.string.bjhzcg));
            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putSerializable("myClientBean", myClientBean);
            intent.putExtras(bundle);
            setResult(RESULT_OK, intent);
        } else {
            showTip(getString(R.string.xzhzcg));
            Bundle bundle = new Bundle();
            bundle.putInt("patientId",addPatient.getPatientid());
            bundle.putInt("type",0);

            if(operaterType == 0 && creditType != CardEnum.ZRXLHZ.getType()){
                if(null != myClientBean){
                    myClientBean.setId(addPatient.getPatientid());
                }
                showActivityForResult(SignQrCodeActivity.class,bundle,Constants.REQUEST_ADD_PATIENT_SIGN);
            }else {
                finish();
            }
        }


    }

    @Override
    public void showTip(String msg) {
        super.showTip(msg);
    }

    public void setText(MyClientBean bean) {
        if(bean.getPhonenum() != null && bean.getPhonenum().contains("-")){
            telType =1;
            tv_tel_type.setText("固定电话");
        }else{
            tv_tel_type.setText("手机号");
        }
//        etName.setEnabled(false);
//        etSfz.setEnabled(false);
        etName.setText(bean.getTruename());
        etSfz.setText(bean.getIdcardnum());
        etSfz.setEnabled(false);
        ll_credit_type.setEnabled(false);
        tv_crdeit_type.setCompoundDrawables(null,null,null,null);

        tv_crdeit_type.setText(CardEnum.getCardName(bean.getCardtype()));
        creditType =bean.getCardtype();

        if (1 == bean.getSex()) {
            tvXb.setText(R.string.nan);
        } else if (2 == bean.getSex()) {
            tvXb.setText(R.string.nv);
        } else {
            tvXb.setText(R.string.zx);
        }

        tvSr.setText(bean.getBirthday());
        etSjh.setText(bean.getPhonenum());
        etXxdz.setText(bean.getAddress());

        etZzys.setText(bean.getDoctorname());
        tvYymc.setText(bean.getHospitalname());
        String blfx = "";//病理分析
        String yyxs = "";//用药线数
        if (!TextUtils.isEmpty(bean.getPathologystr())) {
            Pathology pathology = GsonUtil.GsonToBean(bean.getPathologystr(), Pathology.class);

            type = pathology.getType();
            if (null != type) {
                for (int i = 0; i < type.size(); i++) {
                    Pathology.TypeBean typeBean = type.get(i);
                    if (0 == i || i == type.size()) {
                        blfx += typeBean.getName();
                    } else {
                        blfx += "," + typeBean.getName();
                    }
                }
            }


            severallines = pathology.getSeverallines();
            if (null != severallines) {
                for (int i = 0; i < severallines.size(); i++) {
                    Pathology.SeverallinesBean severallinesBean = severallines.get(i);
                    if (0 == i || i == severallines.size()) {
                        yyxs += severallinesBean.getName();
                    } else {
                        yyxs += "," + severallinesBean.getName();
                    }
                }
            }
        }

        //地址
        if (!TextUtils.isEmpty(bean.getRegionname())) {
            Regionname regionname = GsonUtil.GsonToBean(bean.getRegionname(), Regionname.class);
            if (!TextUtils.isEmpty(regionname.getProvince()) || !TextUtils.isEmpty(regionname.getCity()) || !TextUtils.isEmpty(regionname.getArea())) {
                tvZzqy.setText(regionname.getProvince() + " " + regionname.getCity() + " " + regionname.getArea());
                provinceS = regionname.getProvince();
                cityS = regionname.getCity();
                areaS = regionname.getArea();
            }

        }


        if (0 == bean.getSmokestatus()) {
            //不吸烟
            tvXys.setText(getString(R.string.bxy));
        } else if (1 == bean.getSmokestatus()) {
            //吸烟
            tvXys.setText(getString(R.string.xy) + bean.getSmokeyears());
        } else if (2 == bean.getSmokestatus()) {
            tvXys.setText(getString(R.string.yjy) + bean.getSmokeyears());
        }

        tvBlfx.setText(blfx);
        tvYyxs.setText(yyxs);

        tvScyysj.setText(bean.getFirsttreatment());

        hospitalid = bean.getHospitalid();
    }
}
